<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加班级</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../resources/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../resources/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-header">添加班级信息</div>
    <div class="layui-card-body" style="padding: 15px;">
      <form class="layui-form" action="" lay-filter="add-clazzInfo">

        <div class="layui-form-item">
          <label class="layui-form-label">班级号</label>
          <div class="layui-input-inline">
            <input type="text" name="clazzId" lay-verify="required|studentId" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">班级容量</label>
          <div class="layui-input-inline">
            <input type="text" name="clazzNumber" lay-verify="required" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">班级名称</label>
          <div class="layui-input-inline">
            <input type="text" name="clazzDesc" lay-verify="required" autocomplete="off" class="layui-input">
          </div>
        </div>

        <div class="layui-form-item layui-layout-admin">
          <div class="layui-input-block">
            <div class="layui-footer" style="left: 0;">
              <button class="layui-btn" lay-submit="" lay-filter="add-clazz">立即提交</button>
              <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
          </div>
        </div>

      </form>
    </div>
  </div>
</div>


<script src="../../../resources/layuiadmin/layui/layui.js"></script>
<script src="../../../resources/js/common.js"></script>
<script>
  layui.config({
    base: '../../../resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
            ,layer = layui.layer
            ,form = layui.form;

    form.render(null, 'add-clazzInfo');

    /* 自定义验证规则 */
    form.verify({
      clazzId: function(value){
        if(hasLetter(value) === true || isChina(value) === true){
          return '班级号不能含有英文字母或中文';
        }
      }
    });

    var clazz = {};

    /* 监听提交 */
    form.on('submit(add-clazz)', function(data){

      clazz.clazzId = $('input[name="clazzId"]').val();
      clazz.clazzNumber = $('input[name="clazzNumber"]').val();
      clazz.clazzDesc = $('input[name="clazzDesc"]').val();

      var formData = new FormData();
      formData.append('clazzStr',JSON.stringify(clazz));

      //用ajax时需要注意你的url接口、采用哪一种方式type获取，它的使用的哪种数据类型datatype
      $.ajax({
        url:'/admin/addClazz',
        type:'post',
        data:formData,
        contentType : false,
        processData : false,
        success:function(res){
          if (res.success){
            layer.msg("添加班级信息成功");
          }else {
            layer.msg("添加班级信息失败" + res.errMsg);
          }
        }
      })
      return false;
    });

  });
</script>
</body>
</html>
